package com.alibaba.citrus.ots.platform.enhance.facade.service;

import com.alibaba.citrus.ots.common.annotation.FacadeInvoker;
import com.alibaba.citrus.ots.platform.enhance.functions.company.CompanyEntity;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.otsplatformenhance.api.companywrite.service.CompanyWriteService;
import com.epoch.app.otsplatformenhance.dto.request.OperateCompanyRequest;
import com.epoch.app.otsplatformenhance.sdo.CompanySDO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/9/3 12:26
 */
@Primary
@Service
public class CompanyWriteServiceImpl implements CompanyWriteService {

    @Override
    @FacadeInvoker
    public Result<Boolean> createCompany(CompanySDO request) {
        CompanyEntity companyEntity = CompanyEntity.of(request);
        return companyEntity.doCreate();
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> editCompany(CompanySDO request) {
        CompanyEntity companyEntity = CompanyEntity.of(request);
        return companyEntity.doEdit();
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> enableCompany(OperateCompanyRequest request) {
        CompanySDO sdo = new CompanySDO();
        sdo.setId(request.getId());
        sdo.setVersion(request.getVersion());
        sdo.setOperatorId(request.getOperatorId());
        CompanyEntity companyEntity = CompanyEntity.of(sdo);
        return companyEntity.doEnable();
    }

    @Override
    @FacadeInvoker
    public Result<Boolean> disableCompany(OperateCompanyRequest request) {
        CompanySDO sdo = new CompanySDO();
        sdo.setId(request.getId());
        sdo.setVersion(request.getVersion());
        sdo.setOperatorId(request.getOperatorId());
        CompanyEntity companyEntity = CompanyEntity.of(sdo);
        return companyEntity.doDisable();
    }

}
